use chrono::Local;
use serde::{Deserialize, Serialize};
use sqlx::types::chrono::DateTime;
use struct_field_names_as_array::FieldNamesAsSlice;
use crate::core::serialize_tools::empty_string_as_none;

// 收藏表单数据
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct CollectForm { 
    // 分类id
    pub tid: i64,
    // 名称
    pub name: String, 
    // Url
    pub url: String,
    // 是否显示： 1显示
    pub is_show: i32
}


// 收藏搜索
#[derive(Serialize, Deserialize)]
pub struct CollectListReq {
    pub page: Option<i64>,
    pub page_size: Option<i64>,
    #[serde(default, deserialize_with = "empty_string_as_none")]
    pub tid: Option<i64>,
    #[serde(default, deserialize_with = "empty_string_as_none")]
    pub is_show: Option<i32>,
    pub name: Option<String>
}

// 收藏列表行数据
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct CollectRow { 
    pub id: i64,
    pub name: String, 
    pub url: String,
    pub is_show: i32,
    pub collect_type_name: String,
    pub created_at: DateTime<Local>,
    pub updated_at: DateTime<Local>
}

// 收藏分页结果
#[derive(Serialize, Deserialize)]
pub struct CollectListResp {
    pub paginate: String,
    pub list: Vec<CollectRow>
}
